package top.hzy520.search.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.hzy520.common.constants.Constants;
import top.hzy520.common.resp.ApiResult;
import top.hzy520.search.entity.PageSearch;
import top.hzy520.search.entity.Product;
import top.hzy520.search.service.SearchService;

import java.io.IOException;
import java.util.List;

/**
 * @Author: HouZeYu
 * @Description:
 * @Date: Created in 12:20 2018/6/20
 */
@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    @Qualifier("searchServiceImpl")
    private SearchService searchService;
    /**
    *@Author: HouZeYu
    *@Description: 查询商品
    *@Date: 23:44 2018/6/23
    */
     @RequestMapping("")
    public ApiResult<List<Product>> searchProduct(@RequestBody PageSearch pageSearch) throws IOException {
      ApiResult apiResult=new ApiResult(Constants.RESP_STATUS_OK,"查询成功");
      PageSearch productList=searchService.search(pageSearch);
       apiResult.setData(productList);
      return apiResult;
    }

    /**
    *@Author: HouZeYu
    *@Description: 通过子分类查询商品
    *@Date: 23:45 2018/6/23
    */
    @RequestMapping("/categoryid")
    public ApiResult<List<Product>> searchProductByCategoryId(@RequestBody PageSearch pageSearch) throws IOException {
        ApiResult apiResult=new ApiResult(Constants.RESP_STATUS_OK,"查询成功");
        PageSearch productList=searchService.searchProductByCategoryId(pageSearch);
        apiResult.setData(productList);
        return apiResult;
    }

    /**
     *@Author: HouZeYu
     *@Description: 通过子分类查询商品
     *@Date: 23:45 2018/6/23
     */
    @RequestMapping("/categoryparentid")
    public ApiResult<List<Product>> searchProductByCategoryParentId(@RequestBody PageSearch pageSearch) throws IOException {
        ApiResult apiResult=new ApiResult(Constants.RESP_STATUS_OK,"查询成功");
       PageSearch productList=searchService.searchProductByCategoryParentId(pageSearch);
        apiResult.setData(productList);
        return apiResult;
    }
}
